from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.layout.viewlets.common import ViewletBase
from apkn.workspaces.browser.config import WORKSPACE_SEARCH_FILTERS

class WorkspaceSearchControl(ViewletBase):
    render = ViewPageTemplateFile("templates/search_control.pt")

    @property
    def search_filters(self):
        for filter in WORKSPACE_SEARCH_FILTERS:
            rq_value = self.request.form.get(filter['identity'], None)
            if rq_value is not None:
                filter['selected_value'] = rq_value
        return WORKSPACE_SEARCH_FILTERS

    @property
    def search_terms(self):
        return self.request.form.get('search_query',
         '')
